var vm = new Vue({
    //vue对象节点,指向父盒子
    el:'#register',                                                                   
    //vue实例 的data属性
    data:function(){
    	var validatePass2 = function(rule, value, callback){
            if (value === '') {
              callback(new Error('请再次输入密码'));
            } else if (value !== vm.user.password) {
              callback(new Error('两次输入密码不一致!'));
            } else {
              callback();
            }
          };
          var validatePass = function(rule, value, callback){
              if ($.trim(value) === '') {
                callback(new Error('请输入用户名'));
              } else if ($.trim(value).length >15) {
                callback(new Error('用户名长度不能超过15'));
              } else {
                 var url = "./isUserExist.action";
           	   var params = {
           		   'user.userCode':$.trim(value)
           	   }
           	   pb.ajaxPost(url,params,function(r){
       	       		if(r.isUserExist == true){
       	       		callback(new Error('用户名不可重复'));
       	       		}else{callback();}
       	       });
              }
          };
          var validatePass3 = function(rule, value, callback){
              if (value === '') {
                callback(new Error('请输入手机号'));
              } else if ($.trim(value).length !== 11 ) {
                callback(new Error('手机号为11位'));
              } else {
                callback();
              }
            };
        return{
        	loginLoading:false,
        	user:{},
        	rules:{ 
        		userCode: [{ required: true, message: '请输入用户名', trigger: 'blur' },
        					{validator: validatePass, trigger: 'blur'}],
			   	password: [{ required: true, message: '请输入密码', trigger: 'blur' },
 			   	   { max: 15, message: '长度不能超过15个字符', trigger: 'blur' }],
 			   	rePassword: [{ required: true, message: '请再次输入密码', trigger: 'blur' },
 			   		{validator: validatePass2, trigger: 'blur'},
  			   	   { max: 15, message: '长度不能超过15个字符', trigger: 'blur' }],
  			   	tel: [{ required: true, message: '请输入手机号', trigger: 'blur' },
  			   		{ type: 'number', message: '必须为数字值'},
  			   		{validator: validatePass3, trigger: 'blur'}],
  			   	email: [{ required: true, message: '请输入邮箱', trigger: 'blur' },
   			   	   		{type: 'email', message: '请输入正确的邮箱地址', trigger: 'blur,change'}],
        	}
        };
    },
    //vue实例 的methods
    methods:{
    	register:function(formName){
    		vm.$refs[formName].validate(function(valid) {
    	          if (valid) {
    	        	  vm.loginLoading = true;
	                  var url = './register.action';
	                  var params = {
	                  		"user.userCode":vm.user.userCode,
	                  		"user.userName":vm.user.userName,
	                  		"user.password":vm.user.password,
	                  		"user.tel":vm.user.tel,
	                  		"user.email":vm.user.email
	                  		
	                  };
	                  
	                  pb.ajaxPost(url,params,function(r){
	                	
	                  	if(r.code == '000000'){
	                  		vm.loginLoading = false;
	                  		window.location.href="login.html"; 
	                  	}else{
	                  		vm.loginLoading = false;
	                  		pb.alertErr("注册失败");
	                  	}
	                  	},function(err){
	                  		vm.loginLoading = false;
	                  		pb.alertErr("注册超时");
	                  	});
    	          } else {
    	            return false;
    	          }
    	    });
    	}

    }
    //vue实例 的methods结束
});